#!/bin/bash

HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

getver_c=$(mktemp "${TMPDIR:-/tmp}/getver-XXXXXXX.c")
if [[ $NUMERIC != 1 ]]; then
	cat <<- EOF > $getver_c
		#include <stdio.h>

		#include "src/version.h"

		int main(int argc, char *argv[]) {
				printf("%d.%d.%d\n", REBLOOM_VERSION_MAJOR, REBLOOM_VERSION_MINOR, REBLOOM_VERSION_PATCH);
				return 0;
		}
		EOF
else
	cat <<- EOF > $getver_c
		#include <stdio.h>

		#include "src/version.h"

		int main(int argc, char *argv[]) {
				printf("%d\n", REBLOOM_MODULE_VERSION);
				return 0;
		}
		EOF
fi
prog=$(mktemp "${TMPDIR:-/tmp}/getver.XXXXXXX")
gcc -I$HERE -o $prog $getver_c
ver=`$prog`
rm -f $prog $getver_c
echo $ver
exit 0
